package com.corecloud.controller.sys;

import java.security.Principal;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.corecloud.tools.PageDemo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import com.corecloud.entity.SysLogEntity;
import com.corecloud.service.SysLogService;
import org.springframework.web.servlet.ModelAndView;


/**
 * 系统日志表
 *
 * @author CCW
 * @email 452050507@qq.com
 * @date 2020-09-28 09:04:05
 */
@RestController
@RequestMapping("/syslog")
public class SysLogController {

    @Autowired
    private SysLogService sysLogService;


    /**
     * 日志管理页
     * @param principal 登录用户信息
     * @return
     */
    @RequestMapping("/index")
    public ModelAndView index(Principal principal){
        ModelAndView modelAndView = new ModelAndView("log/index");
        return modelAndView;
    }



    /**
     * 日志管理页数据（分页）
     * @param principal 登录用户信息
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public Page<SysLogEntity> list(Principal principal, SysLogEntity sl, PageDemo pageDemo){
        QueryWrapper<SysLogEntity> qw = new QueryWrapper();
        if(!StringUtils.isEmpty(sl.getUrl())){
            qw.like("url",sl.getUrl());
        }
        if(!StringUtils.isEmpty(sl.getUserName())){
            qw.like("user_name",sl.getUserName());
        }

        OrderItem oi = new OrderItem();
        oi.setAsc(false);
        oi.setColumn("id");
        pageDemo.addOrder(oi);
        return sysLogService.getInfoByPage(pageDemo,qw);
    }



    /**
     * 清除日志-保留三个月内数据，其余全部删除(主动操作)
     */
//    @RequestMapping("/delete")
//    public R delete(@RequestBody Integer[] ids){
//		sysLogService.removeByIds(Arrays.asList(ids));
//
//        return R.ok();
//    }

}
